/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;
import msnclient.Cliente;
import msnclient.Controladora;
import msnclient.OTablaContacto;
import msncommonsc.Contacto;
import msncommonsc.EnumEstado;

/**w
 *
 * @author Agustin
 */
public class msnTableModel extends AbstractTableModel implements OTablaContacto {

    public Object[][] cargarDatos() {

        try {
            List<Contacto> contactos2 = Controladora.getInstancia().obtenerPersona().getMapaContactos();
            contactos = new Contacto[contactos2.size()][1];

            for (int x = 0; x < contactos2.size(); x++) {
                contactos[x][0] = contactos2.get(x);
            }
        } catch (Exception e) {
            throw new UnsupportedOperationException(e.toString());
        }

        return contactos;
    }
    private Object contactos[][] = cargarDatos();

    public Object[][] getContactos() throws RemoteException, NotBoundException {
        return contactos;
    }

    public void setContactos(Object[][] contactos) {
        this.contactos = contactos;
    }

    public int getRowCount() {
        if (contactos.length == 0) {
            return 0;
        } else {
            return contactos.length;
        }
    }

    public int getColumnCount() {
        if (contactos.length == 0) {
            return 0;
        } else {
            return contactos[0].length;
        }
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Object c = new Contacto();
        try {
            c = getContactos()[rowIndex][columnIndex];
        } catch (RemoteException ex) {
            Logger.getLogger(msnTableModel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NotBoundException ex) {
            Logger.getLogger(msnTableModel.class.getName()).log(Level.SEVERE, null, ex);
        }
        return c;
    }

    public void notificarContacto() {
        contactos = cargarDatos();
        try {
            msnConectado.getInstancia().actualizar();
        } catch (RemoteException ex) {
            Logger.getLogger(msnTableModel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NotBoundException ex) {
            Logger.getLogger(msnTableModel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
